﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>临时物料提请-领用</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
    <style type="text/css">
        .linkbutton{margin-left:20px;min-width:85px;}
        table tr td{padding:0px 5px}
    </style>
</head>
<body>
      <div class="panelSection">    
        <div class="easyui-panel " title="查询区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <form id="searchForm" method="post">
	    	<table>
	    		<tr class="divLabel">
                    <td>发动机号:</td>
                    <td>生产订单号:</td>
	    			<td>提请单号:</td>
                    <td>提请单状态:</td>
                    <td>提交时间起:</td>
                    <td>提交时间止:</td>
	    		</tr>
	    		<tr>
	    			<td><input class="easyui-textbox" type="text" name="Machine" style="width: 120px; height: 22px"/></td>
                    <td><input class="easyui-textbox" type="text" name="MfgOrdername" style="width: 120px; height: 22px"/></td>
                    <td><input class="easyui-textbox" type="text" name="billname" style="width: 120px; height: 22px"/></td>
	    			<td><input id="STATUS" name="status" style="width: 120px; height: 22px"/></td>
                    <td><input class="easyui-datebox" type="text" name="startdate" style="width: 120px; height: 22px"/></td>
                    <td><input class="easyui-datebox" type="text" name="enddate" style="width: 120px; height: 22px"/></td>
                    <td><a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchData()">查询</a></td>
	    			<td><a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.searchReset()">重置</a></td>
                    <td></td>
	    		</tr>
	    	</table>
	    </form> 
        </div>
      </div>
      <div class="panelSection">    
        <div class="easyui-panel " title="临时领料提请" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
           <table id="TempMaterialRequestDetailTable" style="height:500px;width:100%"></table>
           <div id="pp" style="float: right" class="easyui-pagination" data-options="   
                 layout:['first','prev','next','last','manual','info'],              
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                     buttons:[{
                            iconCls:'',
                            text:'Go',
                            id:'pageGo'
                    }]
                ">
                    </div>
        </div>
      </div>
      <div class="panelSection">    
        <div class="easyui-panel " title="按钮区域" style="padding:3px;width:100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
            <div style="margin:15px 0px">
              <a href="javascript:void(0)" class="easyui-linkbutton linkbutton" onclick="page.SaveERPUseNumData()">批量领用</a>
            </div>
      </div>
      </div>
      <div id="statusMessage" style="font-size: 14px; height: 40px"></div>
     
</body>
</html>

<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/json2.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script>
/*
创建人：longb
日期：2023-01-06
描述：退库申请单-查看js
*/
    var page = {
        pagetotal: 0,
        pageSize: 20,
        pageNumber: 1,
        editIndex: null,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSTempMaterialRequestHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
            page.addEditCell();
        },
        addEditCell: function () //给easyuigrid新增editcell方法
        {
            $.extend($.fn.datagrid.methods, {
                editCell: function (jq, param) {
                    return jq.each(function () {
                        var opts = $(this).datagrid('options');
                        var fields = $(this).datagrid('getColumnFields', true).concat($(this).datagrid('getColumnFields'));
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor1 = col.editor;
                            if (fields[i] != param.field) {
                                col.editor = null;
                            }
                        }
                        $(this).datagrid('beginEdit', param.index);
                        for (var i = 0; i < fields.length; i++) {
                            var col = $(this).datagrid('getColumnOption', fields[i]);
                            col.editor = col.editor1;
                        }
                    });
                }
            });
        },
        endEditing: function (gridId) {
            if (page.editIndex == undefined) { return true }
            if ($('#' + gridId).datagrid('validateRow', page.editIndex)) {
                $('#' + gridId).datagrid('endEdit', page.editIndex);
                page.editIndex = undefined;
                return true;
            } else {
                return false;
            }
        },
        //页面事件绑定
        bind: function () {
            $('#STATUS').combobox({
                data: [{ id: '0', text: '待提交' }, { id: '1', text: '待确认' }, { id: '2', text: '已确认' }, { id: '3', text: '已出库' }, { id: '4', text: '已完成' }, { id: '', text: '全部'}],
                valueField: 'id',
                textField: 'text',
                value: '3'
            });
            $('#TempMaterialRequestDetailTable').datagrid({
                rownumbers: true,
                nowrap: false,
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pagetotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                frozenColumns: [[
                 { field: 'ZSTEMPMATERIALREQUESTID', width: 10, checkbox: true },
                 { field: 'ZSTEMPMATERIALREQUESTNO', title: '提请单号', width: 170 },
                 { field: 'TMRTYPE', title: '领用类型', width: 100, formatter: function (value, row, index) { if (value == "0") { return 'SCLL|计划外领料'; } else { return 'BFFL|补废领料'; } } },
                 { field: 'MFGORDERNAME', title: '生产订单号', width: 120 },
                 { field: 'MACHINENO', title: '发动机号', width: 80 },
                 { field: 'PRODUCTNAME', title: '物料编码', width: 100 },
                 { field: 'PRODUCTDESCRIPTION', title: '物料名称', width: 90 },
            ]],
                columns: [[
                 { field: 'APPLYNUM', title: '申请数量', width: 90, align: 'center' },
		         { field: 'ERFMG', title: '已出库数量', width: 90, align: 'center' },
                 { field: 'NOERFMG', title: '未出库数量', width: 90,align: 'center', formatter: function (value, row, index) { return row.APPLYNUM - row.ERFMG; } },
                 { field: 'USENUM', title: '已领用数量', width: 90, align: 'center' },
                 { field: 'NOUSENUM', title: '未领用数量', width: 90,align: 'center', editor: { type: 'numberbox' }, styler: function (value, row, index) { return 'background-color:yellow' } },
                 { field: 'STOCKRETURNNUM5', title: '齐套率', width: 70,align: 'center', formatter: function (value, row, index) { return (row.ERFMG / row.APPLYNUM).toFixed(1) + '%'; } },
                 { field: 'TMRREASON', title: '领料原因', width: 200 },
                 { field: 'STATUS', title: '状态', width: 100, formatter: function (value, row, index) { if (value == 2) { return "已确认"; } else if (value == 1) { return "待确认"; } else { return "待提交"; } } },
                 { field: 'CREATEDATENAME', title: '创建人', width: 100 },
                 { field: 'CREATEDATE', title: '创建时间', width: 150 },
                 { field: 'SUBMITNAME', title: '提交人', width: 100 },
                 { field: 'SUBMITDATE', title: '提交时间', width: 150 },
                 { field: 'CONFIRMNAME', title: '确认人', width: 100 },
                 { field: 'CONFIRMDATE', title: '确认时间', width: 150 },
                 { field: 'TMRUSENAME', title: '领用人', width: 100 },
                 { field: 'TMRUSEDATE', title: '领用时间', width: 150 },
                 { field: 'ERPTMRNO', title: 'ERP出库单号', width: 100 },
                 { field: 'xxx', title: '', width: 30 }
	           ]],
                onClickCell: function (index, field) {
                    //编辑单元格
                    var row = $('#TempMaterialRequestDetailTable').datagrid('getRows')[index];
                    if (row.STATUS !== 2) { return; }
                    if (page.endEditing('TempMaterialRequestDetailTable')) {
                        if (field == "NOUSENUM" && row.NOUSENUM>0) {
                            $('#TempMaterialRequestDetailTable').datagrid('editCell', { index: index, field: field });
                            var editor = $(this).datagrid('getEditor', { index: index, field: field }); //获取当前编辑器
                            $(editor.target).next().find('.validatebox-text').focus();
                            page.editIndex = index;
                        }
                    }
                }
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    page.pageSize = pageSize; page.pageNumber = pageNumber;
                    page.getTempMaterialRequestData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = $(this).parents('tr').find('.pagination-num').val();
                page.pageNumber = pageNumber;
                page.getTempMaterialRequestData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.reset(true, true);
                page.pageNumber = 1; page.pagetotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });
        },

        //查询
        searchData: function () {
            page.reset(false, true);
            page.pageNumber = 1;
            page.getTempMaterialRequestData();
            $('#EditorForm').form("clear");
        },
        //查询临时领料提请单信息
        getTempMaterialRequestData: function () {
            var frdata = $('#searchForm').serializeArray();
            var data = {};
            $.each(frdata, function () {
                data[this.name] = this.value
            });
            var param = {
                action: "getTempMaterialRequestDataByPageSize",
                pageSize: page.pageSize,
                pageNumber: page.pageNumber,
                data: JSON.stringify(data)
            };
            page.post(param, function (res) {
                if (res.Result) {
                    //console.info(res);
                    page.pagetotal = res.RowCount;
                    $('#TempMaterialRequestDetailTable').datagrid('loadData', res.DBTable);
                }
            });
        },
        //保存临时领料提请单信息
        SaveERPUseNumData: function () {
            $('#TempMaterialRequestDetailTable').datagrid('acceptChanges');
            var rows = $('#TempMaterialRequestDetailTable').datagrid('getRows');
            var param = {
                action: "updateTempMaterialRequestData",
                type: 'use',
                data: JSON.stringify(rows)
            };
            page.post(param, function (res) {
                if (res.Result) {
                    page.getTempMaterialRequestData();
                }
                displayMessage(res.Message, res.Result);
            });
        },

        //查询重置
        searchReset: function () {
            $('#searchForm').form('clear');
            $('#TempMaterialRequestDetailTable').datagrid('loadData', []);
            //page.bind();
        },

        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            clearMessage();
        },
        //post数据
        post: function (param, callback) {
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                }
            });
        }
    }
$(function () {
    page.init();
});
</script>

